<?php

/*

  Action - Attack	$4

  Gain a silver card, put it on top of your deck.
  Each other player reveals a Victory card from his hand and puts it on his deck (or reveals a hand with no Victory cards).

 */

class Bureaucrat extends Card implements iAction, iKingdom, iAttack, iBasic {

    public function __construct() {
        parent::__construct("Bureaucrat", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }
         
    public function getDescription() {
        return array(
            "Gain a silver card, put it on top of your deck. Each other player reveals a Victory card from his hand and puts it on his deck (or reveals a hand with no Victory cards).");
    }
    
    public function play(Game $game, $isRealCard) {
        $silver = $game->moveCardFromPileToPile("Silver", BoardCards, DrawPile);
         ScreenDisplay::addScreenMessage($game, true, "put " . nicePrint($silver) . " on top of your deck", "puts ".ScreenDisplay::$LMSG." on top of his deck");
        $game->setPhase(Phase_Sleep);

        $game->attack($this);

        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {
            $playHandOther = $game->getPlayHand($name);

            $victory_cards = array();
            foreach ($playHandOther as $card) {
                if ($card instanceof iVictory) {
                    $victory_cards[] = $card;
                }
            }
            $unique = getUniqueCards($victory_cards);

            if (sizeof($unique) > 1) {
                $output = MySocket::GetUserReply($game, Input_ChooseOne, $unique, 1, 1, null, "Choose card to put on your draw deck", $name, true);
            } else if (sizeof($unique) == 1) {
                $card = array_pop($unique);
                $game->moveCardFromPileToPile($card, PlayHand, DrawPile, $name);
                 ScreenDisplay::addScreenMessage($game, true, "put  " . nicePrint($card) . " on top of your deck", "reveals " . ScreenDisplay::$LMSG . " and puts it on top of his deck", $name);
            } else {
                 ScreenDisplay::addScreenMessage($game, true, "reveal  " . nicePrint($playHandOther), "reveals " . ScreenDisplay::$LMSG, $name);
            }
        }

        //the waiting function
        $users_replies = MySocket::getUsersReplies($game);
        foreach ($users_replies as $name => $output) {

            $card_name = $output[0];
            $game->moveCardFromPileToPile($card_name, PlayHand, DrawPile, $name);
             ScreenDisplay::addScreenMessage($game, true, "put  " . nicePrint($card) . " on top of your deck", "reveals " . ScreenDisplay::$LMSG . " and puts it on top if his deck", $name);
            $game->setPhase(Phase_Sleep, $name);
        }
        $game->cardActionFinished();
        return true;
    }

}

?>